<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="股票代码，包含字符" prop="code">
        <el-input
          v-model="queryParams.code"
          placeholder="请输入股票代码，包含字符"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="换手率" prop="hsl">
        <el-input
          v-model="queryParams.hsl"
          placeholder="请输入换手率"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="量比" prop="lb">
        <el-input
          v-model="queryParams.lb"
          placeholder="请输入量比"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="流通市值" prop="ltsz">
        <el-input
          v-model="queryParams.ltsz"
          placeholder="请输入流通市值"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="股票名称" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入股票名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="peTtm">
        <el-input
          v-model="queryParams.peTtm"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="pn">
        <el-input
          v-model="queryParams.pn"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="speed">
        <el-input
          v-model="queryParams.speed"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="state">
        <el-input
          v-model="queryParams.state"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="成交额" prop="turnover">
        <el-input
          v-model="queryParams.turnover"
          placeholder="请输入成交额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="成交量" prop="volume">
        <el-input
          v-model="queryParams.volume"
          placeholder="请输入成交量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="涨跌额" prop="zd">
        <el-input
          v-model="queryParams.zd"
          placeholder="请输入涨跌额"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="涨跌幅" prop="zdf">
        <el-input
          v-model="queryParams.zdf"
          placeholder="请输入涨跌幅"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="zdfD10">
        <el-input
          v-model="queryParams.zdfD10"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="zdfD20">
        <el-input
          v-model="queryParams.zdfD20"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="zdfD5">
        <el-input
          v-model="queryParams.zdfD5"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="zdfD60">
        <el-input
          v-model="queryParams.zdfD60"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="zdfW52">
        <el-input
          v-model="queryParams.zdfW52"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="zdfY">
        <el-input
          v-model="queryParams.zdfY"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="振幅" prop="zf">
        <el-input
          v-model="queryParams.zf"
          placeholder="请输入振幅"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="助力净流入" prop="zljlr">
        <el-input
          v-model="queryParams.zljlr"
          placeholder="请输入助力净流入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="主力流出" prop="zllc">
        <el-input
          v-model="queryParams.zllc"
          placeholder="请输入主力流出"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="主力五日流出" prop="zllcD5">
        <el-input
          v-model="queryParams.zllcD5"
          placeholder="请输入主力五日流出"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="主力流入" prop="zllr">
        <el-input
          v-model="queryParams.zllr"
          placeholder="请输入主力流入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="主力五日流入" prop="zllrD5">
        <el-input
          v-model="queryParams.zllrD5"
          placeholder="请输入主力五日流入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="${comment}" prop="zsz">
        <el-input
          v-model="queryParams.zsz"
          placeholder="请输入${comment}"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最新价" prop="zxj">
        <el-input
          v-model="queryParams.zxj"
          placeholder="请输入最新价"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:day:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:day:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:day:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:day:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="dayList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="股票代码，包含字符" align="center" prop="code" />
      <el-table-column label="换手率" align="center" prop="hsl" />
      <el-table-column label="量比" align="center" prop="lb" />
      <el-table-column label="流通市值" align="center" prop="ltsz" />
      <el-table-column label="股票名称" align="center" prop="name" />
      <el-table-column label="${comment}" align="center" prop="peTtm" />
      <el-table-column label="${comment}" align="center" prop="pn" />
      <el-table-column label="${comment}" align="center" prop="speed" />
      <el-table-column label="${comment}" align="center" prop="state" />
      <el-table-column label="${comment}" align="center" prop="stockType" />
      <el-table-column label="成交额" align="center" prop="turnover" />
      <el-table-column label="成交量" align="center" prop="volume" />
      <el-table-column label="涨跌额" align="center" prop="zd" />
      <el-table-column label="涨跌幅" align="center" prop="zdf" />
      <el-table-column label="${comment}" align="center" prop="zdfD10" />
      <el-table-column label="${comment}" align="center" prop="zdfD20" />
      <el-table-column label="${comment}" align="center" prop="zdfD5" />
      <el-table-column label="${comment}" align="center" prop="zdfD60" />
      <el-table-column label="${comment}" align="center" prop="zdfW52" />
      <el-table-column label="${comment}" align="center" prop="zdfY" />
      <el-table-column label="振幅" align="center" prop="zf" />
      <el-table-column label="助力净流入" align="center" prop="zljlr" />
      <el-table-column label="主力流出" align="center" prop="zllc" />
      <el-table-column label="主力五日流出" align="center" prop="zllcD5" />
      <el-table-column label="主力流入" align="center" prop="zllr" />
      <el-table-column label="主力五日流入" align="center" prop="zllrD5" />
      <el-table-column label="${comment}" align="center" prop="zsz" />
      <el-table-column label="最新价" align="center" prop="zxj" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:day:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:day:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改每日行情对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="股票代码，包含字符" prop="code">
          <el-input v-model="form.code" placeholder="请输入股票代码，包含字符" />
        </el-form-item>
        <el-form-item label="换手率" prop="hsl">
          <el-input v-model="form.hsl" placeholder="请输入换手率" />
        </el-form-item>
        <el-form-item label="量比" prop="lb">
          <el-input v-model="form.lb" placeholder="请输入量比" />
        </el-form-item>
        <el-form-item label="流通市值" prop="ltsz">
          <el-input v-model="form.ltsz" placeholder="请输入流通市值" />
        </el-form-item>
        <el-form-item label="股票名称" prop="name">
          <el-input v-model="form.name" placeholder="请输入股票名称" />
        </el-form-item>
        <el-form-item label="${comment}" prop="peTtm">
          <el-input v-model="form.peTtm" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="pn">
          <el-input v-model="form.pn" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="speed">
          <el-input v-model="form.speed" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="state">
          <el-input v-model="form.state" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="成交额" prop="turnover">
          <el-input v-model="form.turnover" placeholder="请输入成交额" />
        </el-form-item>
        <el-form-item label="成交量" prop="volume">
          <el-input v-model="form.volume" placeholder="请输入成交量" />
        </el-form-item>
        <el-form-item label="涨跌额" prop="zd">
          <el-input v-model="form.zd" placeholder="请输入涨跌额" />
        </el-form-item>
        <el-form-item label="涨跌幅" prop="zdf">
          <el-input v-model="form.zdf" placeholder="请输入涨跌幅" />
        </el-form-item>
        <el-form-item label="${comment}" prop="zdfD10">
          <el-input v-model="form.zdfD10" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="zdfD20">
          <el-input v-model="form.zdfD20" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="zdfD5">
          <el-input v-model="form.zdfD5" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="zdfD60">
          <el-input v-model="form.zdfD60" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="zdfW52">
          <el-input v-model="form.zdfW52" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="${comment}" prop="zdfY">
          <el-input v-model="form.zdfY" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="振幅" prop="zf">
          <el-input v-model="form.zf" placeholder="请输入振幅" />
        </el-form-item>
        <el-form-item label="助力净流入" prop="zljlr">
          <el-input v-model="form.zljlr" placeholder="请输入助力净流入" />
        </el-form-item>
        <el-form-item label="主力流出" prop="zllc">
          <el-input v-model="form.zllc" placeholder="请输入主力流出" />
        </el-form-item>
        <el-form-item label="主力五日流出" prop="zllcD5">
          <el-input v-model="form.zllcD5" placeholder="请输入主力五日流出" />
        </el-form-item>
        <el-form-item label="主力流入" prop="zllr">
          <el-input v-model="form.zllr" placeholder="请输入主力流入" />
        </el-form-item>
        <el-form-item label="主力五日流入" prop="zllrD5">
          <el-input v-model="form.zllrD5" placeholder="请输入主力五日流入" />
        </el-form-item>
        <el-form-item label="${comment}" prop="zsz">
          <el-input v-model="form.zsz" placeholder="请输入${comment}" />
        </el-form-item>
        <el-form-item label="最新价" prop="zxj">
          <el-input v-model="form.zxj" placeholder="请输入最新价" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listDay, getDay, delDay, addDay, updateDay } from "@/api/system/day"

export default {
  name: "Day",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 每日行情表格数据
      dayList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        code: null,
        hsl: null,
        lb: null,
        ltsz: null,
        name: null,
        peTtm: null,
        pn: null,
        speed: null,
        state: null,
        stockType: null,
        turnover: null,
        volume: null,
        zd: null,
        zdf: null,
        zdfD10: null,
        zdfD20: null,
        zdfD5: null,
        zdfD60: null,
        zdfW52: null,
        zdfY: null,
        zf: null,
        zljlr: null,
        zllc: null,
        zllcD5: null,
        zllr: null,
        zllrD5: null,
        zsz: null,
        zxj: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询每日行情列表 */
    getList() {
      this.loading = true
      listDay(this.queryParams).then(response => {
        this.dayList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        code: null,
        hsl: null,
        lb: null,
        ltsz: null,
        name: null,
        peTtm: null,
        pn: null,
        speed: null,
        state: null,
        stockType: null,
        turnover: null,
        volume: null,
        zd: null,
        zdf: null,
        zdfD10: null,
        zdfD20: null,
        zdfD5: null,
        zdfD60: null,
        zdfW52: null,
        zdfY: null,
        zf: null,
        zljlr: null,
        zllc: null,
        zllcD5: null,
        zllr: null,
        zllrD5: null,
        zsz: null,
        zxj: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加每日行情"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getDay(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改每日行情"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateDay(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addDay(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除每日行情编号为"' + ids + '"的数据项？').then(function() {
        return delDay(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/day/export', {
        ...this.queryParams
      }, `day_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
